home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / dirut / djm_size.zip / SIZE.C < prev    next >
Text File  |  1989-08-07  |  2KB  |  74 lines

  1. /* Program SIZE
  2.  
  3.    D.J. Murphy  August 1989
  4.  
  5.    Used as a pipe for the DOS DIR command in full list (i.e. not using
  6.    either the /W or /P switches) mode to report total directory size.
  7.  
  8.    Usage: DIR [d:\path]|SIZE [/N]
  9.  
  10.    Prints directory listing, then size report afterwards, unless /N switch
  11.    selected, in which case size only is reported.
  12.  
  13.    DIR reports file sizes in columns 14-21 inclusive of the resultant list.
  14.  
  15.    Turbo C v1.5 compile options: No FP
  16.                  Tiny memory model
  17.                  Register variables
  18.                  optimize for size
  19.  
  20. */
  21.  
  22. /************ HEADERS *****************/
  23. #include <stdio.h>
  24. #include <stdlib.h>
  25. #include <string.h>
  26.  
  27. /************ DEFINES *****************/
  28. #define COLSTART 13
  29. #define COLEND   20
  30. #define REJECT   "<DIR>"         /* disregard lines with this */
  31. #define TRMNT    "bytes free"    /* last line */
  32.  
  33. /**************************************/
  34.  
  35. main(argc, argv)
  36.  
  37. int argc;
  38. char *argv[];
  39.  
  40. {
  41.  char line[40];                /* Readin line and file size */
  42.  unsigned long int sum, factor;
  43.  int  ccount, lcount;
  44.  int  eflag = 0;               /* End flag */
  45.  
  46.  sum = 0;
  47.  ccount = lcount = 0;
  48.  
  49.  do {
  50.     gets(line);
  51.     lcount++;
  52.     if (lcount > 4) {
  53.        if (!strstr(line,TRMNT)) {       /* "bytes free" not found */
  54.       if (!strstr(line,REJECT)) {   /* "<DIR>" not found */
  55.              factor = 1;
  56.              for (ccount = COLEND; ccount >= COLSTART; ccount--) {
  57.                  if (line[ccount] != ' ') {
  58.                     sum += ((line[ccount] - '0') * factor);
  59.             factor *= 10;
  60.                  } else
  61.          ccount = COLSTART - 1;
  62.              }
  63.           }
  64.        } else
  65.      eflag = 1;
  66.     }
  67.     if (argc == 1)
  68.        printf("%s\n", line);
  69.  } while(!eflag);
  70.  
  71.  printf("\nDirectory size %lu bytes\n", sum);
  72.  
  73. }
  74.